﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace MediaOwl.Common.Converters
{
    public class TimeSpanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double ms;
            if (double.TryParse(value.ToString(), out ms))
            {
                var ts = TimeSpan.FromMilliseconds(ms);
                return ts.ToString("T");
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}